; SERVER

(defun make-stream-and-talk (handle)
  (let ((stream (make-instance 'comm:socket-stream
                               :socket handle
                               :direction :io
                               :element-type
                                  'base-char)))
  (mp:process-run-function (format nil "talk ~D"
                                   handle)
                           '()
                           'talk-on-stream stream)))

(defun talk-on-stream (stream)
  (unwind-protect
      (loop for line = (read-line stream nil nil)
            while line
            do
            (format stream "You sent: '~A'~%" line)
            (force-output stream))
      (close stream)))

(comm:start-up-server :function 'make-stream-and-talk
                      :service 10244)


; CLIENT

(defun talking-to-myself ()
  (with-open-stream 
      (talk (comm:open-tcp-stream "progpc37.vub.ac.be." 
                                  10244))
    (dolist (monolog 
             '("Hello self."
               "Why don't you say something original?"
               "Talk to you later then.  Bye."))
      (write-line monolog talk)
      (force-output talk)
      (format t "I said: \"~A\"~%"
              monolog)
      (format t "Self replied: \"~A\"~%"
              (read-line talk nil nil)))))
(talking-to-myself)